package core

import (
	"fmt"
	"gvb-server/config"
	"gvb-server/global"
	"io/ioutil"
	"log"

	"gopkg.in/yaml.v2"
)

// 读取yaml文件配置
func InitConfig() {
	const ConfigFile = "setting.yaml"
	c := &config.Config{}
	yamlConf, err := ioutil.ReadFile(ConfigFile) // 读取配置

	if err != nil {
		panic(fmt.Errorf("get configYaml err: %v", err))
	}

	err = yaml.Unmarshal(yamlConf, c)

	if err != nil {
		log.Fatalf("config init Unmarshal: %v", err)
	}

	log.Println("config init success!")
	fmt.Println("config init success!")

	global.Config = c // 赋给全局
}
